﻿using System;
using System.Data.SQLite;
using System.Collections.Generic;

public class SchoolManager
{
    private string connectionString = "Data Source=school.db;Version=3;";

    public void AddSchool(string name)
    {
        using (var connection = new SQLiteConnection(connectionString))
        {
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = "INSERT INTO Schools (Name) VALUES (@name);";
            command.Parameters.AddWithValue("@name", name);
            command.ExecuteNonQuery();
        }
    }

    public void AddClass(string name, int schoolId)
    {
        using (var connection = new SQLiteConnection(connectionString))
        {
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = "INSERT INTO Classes (Name, SchoolId) VALUES (@name, @schoolId);";
            command.Parameters.AddWithValue("@name", name);
            command.Parameters.AddWithValue("@schoolId", schoolId);
            command.ExecuteNonQuery();
        }
    }

    public void AddStudent(string name, int classId)
    {
        using (var connection = new SQLiteConnection(connectionString))
        {
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = "INSERT INTO Students (Name, ClassId) VALUES (@name, @classId);";
            command.Parameters.AddWithValue("@name", name);
            command.Parameters.AddWithValue("@classId", classId);
            command.ExecuteNonQuery();
        }
    }

    public void LogOperation(string operation)
    {
        using (var connection = new SQLiteConnection(connectionString))
        {
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = "INSERT INTO Logs (Operation) VALUES (@operation);";
            command.Parameters.AddWithValue("@operation", operation);
            command.ExecuteNonQuery();
        }
    }

    public void ShowLogs()
    {
        using (var connection = new SQLiteConnection(connectionString))
        {
            connection.Open();
            var command = connection.CreateCommand();
            command.CommandText = "SELECT Id, Operation, Timestamp FROM Logs;";
            var reader = command.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine($"Id: {reader.GetInt32(0)}, Operation: {reader.GetString(1)}, Timestamp: {reader.GetDateTime(2)}");
            }
        }
    }
}